<template>
  <div>
    <el-form ref="form" :rules="rules" :model="form" label-width="0px">
      <el-form-item label="" prop="contents">
        <el-input
          type="textarea"
          v-model="form.contents"
          :rows="6"
          placeholder="请输入评论内容"
          maxlength="1000"
          show-word-limit
        ></el-input>
      </el-form-item>
      <el-button
        type="primary"
        size="small"
        v-preventReClick
        :disabled="!topicStatus"
        @click="submitForm('form')"
        >提 交</el-button
      >
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        pid: '0', //父级节点(评价类型不传)
        topicId: '', //话题ID
        contents: '',
        status: '0', //状态;0-显示，1-不显示
      },
      rules: {
        contents: [
          { required: true, message: '请输入评论内容', trigger: 'blur' },
        ],
      },
    }
  },
  props: ['row', 'topicStatus'],
  mounted() {
    this.form.topicId = this.row.id
  },
  methods: {
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.add()
        }
      })
    },
    //新增
    async add() {
      await this.$store.dispatch('addBbsComment', this.form)
      this.$bus.$emit('refreshBbsCommentList')
      this.form.contents = ''
    },
  },
}
</script>
<style scoped lang="scss">
</style>